package com.neuedu.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neuedu.po.UserinfoPO;
import com.neuedu.service.UserinfoService;
import com.neuedu.vo.ValidateResultVO;

@Controller
public class UserHandler {
	
	@Autowired
	private UserinfoService us;
	
	@RequestMapping("/getMyUserinfo.do")
	@ResponseBody
	public UserinfoPO getMyUserinfo(HttpSession session) throws Exception{
		UserinfoPO po = (UserinfoPO) session.getAttribute("online");
		String userid = po.getUserid();
		UserinfoPO u = us.getUserinfoByUserID(userid);
		return u;
	}
	
	@RequestMapping("/validateUser.do")
	@ResponseBody
	public ValidateResultVO validateUser(UserinfoPO po, HttpSession session) throws Exception{
		String userid = ((UserinfoPO)session.getAttribute("online")).getUserid();
		po.setUserid(userid);
		ValidateResultVO vo = us.validateUserAccount(po);
		return vo;
	}
	
	@RequestMapping("/updateUser.do")
	@ResponseBody
	public int updateUser(UserinfoPO po, HttpSession session) throws Exception{
		String userid = ((UserinfoPO)session.getAttribute("online")).getUserid();
		po.setUserid(userid);
		int r = us.updateUseinfo(po);
		return r;
	}
	

}
